//
//  BankListView.m
//  WBBaseProject
//
//  Created by xiaozhi on 2018/4/17.
//  Copyright © 2018年 吴斌. All rights reserved.
//

#import "BankListView.h"
#import "BankTableViewCell.h"

@implementation BankListView

- (void)awakeFromNib
{
    [super awakeFromNib];
    
    self.bankTable.delegate = self;
    self.bankTable.dataSource = self;
    self.bankTable.tableFooterView = [self footV];
    [self.bankTable registerNib:[UINib nibWithNibName:@"BankTableViewCell" bundle:nil] forCellReuseIdentifier:@"BankTableViewCell"];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (void)setBankdata:(NSArray *)bankdata
{
    _bankdata = bankdata;
    [self.bankTable reloadData];
}
- (IBAction)cancle:(id)sender {
    
}
- (IBAction)confirm:(id)sender {
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    BankTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BankTableViewCell" forIndexPath:indexPath];
    
    NSDictionary *dic = self.bankdata[indexPath.row];
    
    [cell configData:dic];
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.bankdata.count;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dic = self.bankdata[indexPath.row];
    
    if(self.chooseBank){
        
        [XYHttpRequest dataRequestSetDefaultBankCardWithCardType:0 cardId:dic[@""] success:^(id responseObj) {
            
            if (Success) {
                self.chooseBank(dic);
            }
        } failure:^(NSError *error) {
            
        }];
        
    }
}
- (UIView*)footV
{
    UIView *foot = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 60)];
    foot.backgroundColor = [UIColor whiteColor];
    
    UIImageView *ima = [[UIImageView alloc]init];
    ima.image = [UIImage imageNamed:@"addCard"];
    [foot addSubview:ima];
    [ima mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(15);
        make.centerY.equalTo(0);
        make.width.height.equalTo(30);
    }];
    
    UILabel *la = [[UILabel alloc]init];
    la.font= WB_FontSize(14);
    la.text = @"使用新卡充值";
    [foot addSubview:la];
    [la mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(ima.right).offset(10);
        make.top.bottom.equalTo(0);
    }];
    
    UIButton *btn = [[UIButton alloc]init];
    [foot addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(0);
    }];
    [btn addTarget:self action:@selector(toAddCard) forControlEvents:UIControlEventTouchUpInside];
    
    return foot;
}
- (void)toAddCard
{
    if (self.addCard) {
        self.addCard();
    }
}
@end
